import React from 'react';
import { postSofCashRegisterAccount} from '../../../../api'
import { collectionTypeEnum } from "../../../../enum";
import { Modal, Form, InputNumber, DatePicker, message, Select } from 'antd'
import moment from 'moment'
const { Option } = Select;

/**
 * @description: 费用收纳-押金-退款窗口
 * @author: xiaoxujs
 * @updata: xiaoxujs（2021-07-28） 创建
 */

const RegisterMoney = ({ setRegisterMoneyShow, registerMoneyShow, clickId, listFun }) => {
    const [form] = Form.useForm()
    const { validateFields, resetFields } = form
    const handleOk = () => {
        validateFields().then(values => {
            values.actAccountsDate = moment(values.actAccountsDate).format('YYYY-MM-DD')
            values.id = clickId
            ; (async () => {
                const { code, msg } = await postSofCashRegisterAccount(values)
                if (code === '20000') {
                    message.success('登记到账成功!')
                    listFun()
                    resetFields()
                    setRegisterMoneyShow(false);
                } else {
                    message.error(msg)
                }
            })()
        })
    };

    const handleCancel = () => {
        resetFields()
        setRegisterMoneyShow(false);
    };
    return <Modal
        title="登记到账"
        visible={registerMoneyShow}
        onOk={handleOk}
        onCancel={handleCancel}
    >
        <Form
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 16 }}
            form={form}
        >
            <Form.Item
                label="到账金额（元）"
                name="actAccounts"
                rules={[{ required: true, message: '请输入到账金额!' }]}
            >
                <InputNumber />
            </Form.Item>
            <Form.Item
                label="到账时间"
                name="actAccountsDate"
                rules={[{ required: true, message: '请选择到账时间!' }]}
            >
                <DatePicker />
            </Form.Item>
            <Form.Item
                label="到账方式"
                name="paymentTerm"
                rules={[{ required: true, message: '请选择到账方式!' }]}
            >
                    <Select style={{ width: 120 }} >
                        {
                            collectionTypeEnum.map(item => <Option value= {item.value} key = {item.value}>{item.babel}</Option>)
                        }
      
                    </Select>
            </Form.Item>
        </Form>
    </Modal>
}

export default RegisterMoney;